home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / slip / cslip-2.6 / tip / hunt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-03  |  3.2 KB  |  118 lines

  1. /*
  2.  * Copyright (c) 1983 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that: (1) source distributions retain this entire copyright
  7.  * notice and comment, and (2) distributions including binaries display
  8.  * the following acknowledgement:  ``This product includes software
  9.  * developed by the University of California, Berkeley and its contributors''
  10.  * in the documentation or other materials provided with the distribution
  11.  * and in all advertising materials mentioning features or use of this
  12.  * software. Neither the name of the University nor the names of its
  13.  * contributors may be used to endorse or promote products derived
  14.  * from this software without specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  */
  19.  
  20. #ifndef lint
  21. static char sccsid[] = "@(#)hunt.c    5.4 (Berkeley) 9/2/88";
  22. #endif /* not lint */
  23.  
  24. #include "tip.h"
  25.  
  26. extern char *getremote();
  27. extern char *rindex();
  28.  
  29. static    jmp_buf deadline;
  30. static    int deadfl;
  31.  
  32. char uucplock[BUFSIZ];
  33.  
  34. dead()
  35. {
  36.  
  37.     deadfl = 1;
  38.     longjmp(deadline, 1);
  39. }
  40.  
  41. hunt(name)
  42.     char *name;
  43. {
  44.     register char *cp, *cf, *ct;
  45.     sigfunc_t (*f)();
  46.  
  47.     f = signal(SIGALRM, dead);
  48.     while (cp = getremote(name)) {
  49.         /*
  50.          * The name of the lock is pretty important. We don't
  51.          * want to introduce the following security problems:
  52.          * 1. Namecollision in lock file between different devices
  53.          * 2. uucplock is used to decide whether or not to call
  54.          *    acucntrl. Thus, non-/dev devices should have a different
  55.          *    lock name than devices in /dev.
  56.          */
  57.         if (*cp != '/')    /* device name must be absolute path */
  58.             continue;
  59.         while (*cp == '/') cp++;
  60.         cp--;
  61.         if (strncmp("/dev/", cp, 5) == 0) {
  62.             cf = cp + 5;
  63.             while (*cf == '/') cf++;
  64.         } else
  65.             cf = cp;
  66.         ct = uucplock;
  67.         while (*cf) {
  68.             if (*cf == '/') {
  69.                 if (ct == uucplock
  70.                     || (ct > uucplock && *(ct-1) != '_'))
  71.                     *ct++ = '_';
  72.             } else
  73.                 *ct++ = *cf;
  74.             cf++;
  75.         }
  76.         *ct = '\0';
  77.         /*
  78.          * At this point we are guranteed that any devices outside
  79.          * /dev will have a lock name starting with underscore (_),
  80.          * and that any slashes (/) in the pathname have been changed
  81.          * to underscores, and that multiple slashes are only made
  82.          * into a single underscore. Thus, any way of expressing
  83.          * a pathname will lead to a unique lock file name.
  84.          */
  85.         deadfl = 0;
  86.         if (uu_lock(uucplock) < 0)
  87.             continue;
  88.         /*
  89.          * Straight through call units, such as the BIZCOMP,
  90.          * VADIC and the DF, must indicate they're hardwired in
  91.          *  order to get an open file descriptor placed in FD.
  92.          * Otherwise, as for a DN-11, the open will have to
  93.          *  be done in the "open" routine.
  94.          */
  95.         if (!HW)
  96.             break;
  97.         if (setjmp(deadline) == 0) {
  98.             alarm(10);
  99.             FD = open(cp, O_RDWR);
  100.         }
  101.         alarm(0);
  102.         if (FD < 0) {
  103.             perror(cp);
  104.             deadfl = 1;
  105.         }
  106.         if (!deadfl) {
  107.             if (!slip)
  108.                 ioctl(FD, TIOCEXCL, 0);
  109.             ioctl(FD, TIOCHPCL, 0);
  110.             signal(SIGALRM, SIG_DFL);
  111.             return ((int)cp);
  112.         }
  113.         (void)uu_unlock(uucplock);
  114.     }
  115.     signal(SIGALRM, f);
  116.     return (deadfl ? -1 : (int)cp);
  117. }
  118.